package com.ryl.yomall.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @Date 9:48
 * @Author ryl
 * java配置类,基于延迟插件
 */
@Configuration
public class DelayMQConfig {
    public static final String exchange_delay = "exchange.delay";
    public static final String routing_delay = "routing.delay";
    public static final String queue_delay_1 = "queue.delay.1";

    @Bean
    public Queue queueDelay(){
        return QueueBuilder.durable ( queue_delay_1 ).build ();
    }
    @Bean
    public Exchange exchangeDelay(){
        Map<String, Object> args=new HashMap<> (  );
        args.put ( "x-delayed-type","direct" );
        //这里要自定义一个交换机
        return new CustomExchange (exchange_delay,"x-delayed-message",true,false,args  );
    }
    @Bean
    public Binding bindingDelay(){
        return BindingBuilder.bind ( queueDelay() ).to ( exchangeDelay() ).with (routing_delay  ).noargs ();
    }

}
